package controller

import (
	"digital/server/common"
	"digital/server/model"
	"digital/server/response"
	"github.com/gin-gonic/gin"
	"net/http"
)

// 公告详情展示接口
func GetNotice(ctx *gin.Context) {
	noticeID := ctx.PostForm("noticeID")
	var notice model.Notice
	// 构建数据库查询条件
	DB := common.GetDB()
	DB.Where("nid = ? ", noticeID).First(&notice)
	var user model.User
	DB.Where("uid=?", notice.Uid).First(&user)
	if notice.Nid == 0 {
		ctx.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "公告不存在",
		})
		return
	}
	noticeResponse := gin.H{
		"Nid":     notice.Nid,
		"Ntime":   notice.Ntime,
		"Sender":  notice.Sender,
		"Uid":     notice.Uid,
		"Title":   notice.Title,
		"Content": notice.Content,
		"Path":    notice.Path,
		"Author":  user.Uname,
	}
	response.Success(ctx, gin.H{"notice": noticeResponse}, "查询成功")
}
